package com.igame.Controller;


import com.igame.Service.GoodsService;
import com.igame.Service.InformationService;
import com.igame.Service.UserService;
import com.igame.common.PageResult;
import com.igame.common.Result;
import com.igame.dto.InformationPageDto;
import com.igame.entity.Information;
import com.igame.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.math.BigDecimal;
import java.util.List;

@CrossOrigin //忽视跨域问题
@RestController
@RequestMapping("/information")
public class InformationController {
    @Autowired
    InformationService informationService;

    @Autowired
    UserService userService;

    @PostMapping("/uploadInformation")
    public Result upload(@RequestParam("title") String title,
                         @RequestParam("content") String content,
                         @RequestParam("userId") Integer userId,
                         @RequestPart(value = "image", required = false) MultipartFile image){

        return informationService.addInformation(title,content,userId,image);
    }

    @PostMapping("/InformationPage")
    public Result<PageResult> page(@RequestBody InformationPageDto informationPageDto){
        PageResult pageResult = informationService.pageQuery(informationPageDto);
        return Result.success(pageResult);
    }

    @PostMapping("/getInformationById")
    public Result<Information> getInformationById(@RequestBody Integer id){
        return informationService.getInformationById(id);
    }

    @PostMapping("/getUsername")
    public Result<UserVo> getUserName(@RequestBody Integer id){
        return userService.getUserById(id);
    }


}
